﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Transactions.*;
    import Events.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;

    public class TBuyCrew extends Transaction {

        private static var m_alreadySeenThisSession:Boolean = false;

        private var m_targetObjectId:Number;
        private var m_cost:Number;
        private var m_cash:Number;
        private var m_gateName:String;

        public function TBuyCrew(_arg1:Number, _arg2:Number, _arg3:Number, _arg4:String=""){
            var _local6:GameObject;
            super();
            this.m_targetObjectId = _arg1;
            this.m_cost = _arg2;
            this.m_gateName = _arg4;
            var _local5:Boolean;
            if ((((_arg2 > 0)) && ((Global.player.gold >= _arg2)))){
                Global.player.gold = (Global.player.gold - _arg2);
                _local5 = true;
            } else {
                if ((((_arg3 > 0)) && ((Global.player.cash >= _arg3)))){
                    Global.player.cash = (Global.player.cash - _arg3);
                    _local5 = true;
                };
            };
            if (_local5){
                Global.crews.addCrewById(_arg1, "-1");
                _local6 = (Global.world.getObjectById(_arg1) as GameObject);
                if (_local6){
                    _local6.onAddCrewMember();
                };
                Global.ui.dispatchEvent(new GenericObjectEvent(GenericObjectEvent.CREW_PURCHASE, null));
            };
        }
        override public function perform():void{
            signedCall("UserService.purchaseCrewMember", this.m_targetObjectId, this.m_gateName);
        }
        override protected function onComplete(_arg1:Object):void{
            if ((((_arg1 == "purchaseCrewMember_refresh")) && (!(m_alreadySeenThisSession)))){
                UI.displayMessage(ZLoc.t("Main", "FriendsRespondedAlready"), GenericPopup.TYPE_OK, GameUtil.refreshUserState, "", true);
                m_alreadySeenThisSession = true;
            };
        }

    }
}//package Transactions 
